import Foundation
import Testing

@testable import HaishinKit

@Suite struct ISOTypeBufferUtilTests {
    @Test func toNALFileFormat_4() {
        var data = Data([0, 0, 0, 1, 10, 10, 0, 0, 0, 1, 3, 3, 2, 0, 0, 0, 1, 5, 5, 5])
        ISOTypeBufferUtil.toNALFileFormat(&data)
        #expect(data.bytes == Data([0, 0, 0, 2, 10, 10, 0, 0, 0, 3, 3, 3, 2, 0, 0, 0, 3, 5, 5, 5]).bytes)
    }

    @Test func toNALFileFormat_3() {
        var data = Data([0, 0, 1, 10, 10, 0, 0, 1, 3, 3, 2, 0, 0, 1, 5, 5, 5])
        ISOTypeBufferUtil.toNALFileFormat(&data)
        #expect(data.bytes == Data([0, 0, 2, 10, 10, 0, 0, 3, 3, 3, 2, 0, 0, 3, 5, 5, 5]).bytes)
    }

    @Test func toNALFileFormat() {
        let expected = Data([0, 0, 1, 17, 33, 248, 224, 9, 224, 183, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159])
        var data = expected
        data[0] = 0
        data[1] = 0
        data[2] = 0
        data[3] = 1
        ISOTypeBufferUtil.toNALFileFormat(&data)
        #expect(data.bytes == expected.bytes)
    }

    @Test func toNALFileFormat_3video() {
        var data = Data([0, 0, 1, 33, 254, 120, 9, 224, 183, 253, 84, 22, 127, 170, 130, 207, 245, 80, 70, 125, 76, 125, 95, 250, 168, 44, 255, 85, 5, 159, 234, 160, 160, 250, 147, 253, 84, 22, 127, 170, 130, 195, 235, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 8, 143, 168, 175, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 34, 62, 162, 191, 213, 65, 17, 248, 175, 245, 80, 153, 248, 103, 253, 84, 17, 31, 81, 95, 234, 160, 179, 253, 84, 16, 31, 148, 250, 159, 253, 84, 16, 31, 140, 255, 85, 4, 71, 226, 191, 213, 65, 89, 255, 253, 84, 16, 31, 140, 255, 85, 5, 159, 234, 160, 179, 253, 84, 50, 125, 103, 225, 47, 245, 80, 89, 254, 170, 29, 63, 31, 254, 170, 11, 63, 213, 65, 17, 245, 21, 254, 170, 27, 63, 16, 125, 68, 64, 201, 255, 213, 65, 81, 245, 95, 234, 161, 243, 234, 52, 87, 245, 80, 225, 245, 8, 127, 170, 130, 207, 245, 80, 86, 127, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 67, 199, 212, 199, 226, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 21, 31, 175, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 39, 213, 255, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 224])

        ISOTypeBufferUtil.toNALFileFormat(&data)
        #expect(data.bytes == Data([0, 1, 73, 33, 254, 120, 9, 224, 183, 253, 84, 22, 127, 170, 130, 207, 245, 80, 70, 125, 76, 125, 95, 250, 168, 44, 255, 85, 5, 159, 234, 160, 160, 250, 147, 253, 84, 22, 127, 170, 130, 195, 235, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 8, 143, 168, 175, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 34, 62, 162, 191, 213, 65, 17, 248, 175, 245, 80, 153, 248, 103, 253, 84, 17, 31, 81, 95, 234, 160, 179, 253, 84, 16, 31, 148, 250, 159, 253, 84, 16, 31, 140, 255, 85, 4, 71, 226, 191, 213, 65, 89, 255, 253, 84, 16, 31, 140, 255, 85, 5, 159, 234, 160, 179, 253, 84, 50, 125, 103, 225, 47, 245, 80, 89, 254, 170, 29, 63, 31, 254, 170, 11, 63, 213, 65, 17, 245, 21, 254, 170, 27, 63, 16, 125, 68, 64, 201, 255, 213, 65, 81, 245, 95, 234, 161, 243, 234, 52, 87, 245, 80, 225, 245, 8, 127, 170, 130, 207, 245, 80, 86, 127, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 67, 199, 212, 199, 226, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 21, 31, 175, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 39, 213, 255, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 253, 84, 22, 127, 170, 130, 207, 245, 80, 89, 254, 170, 11, 63, 213, 65, 103, 250, 168, 44, 255, 85, 5, 159, 234, 160, 179, 224]).bytes)
    }
}
